Search

在 C# 要輸出正負符號,一個 Format 運算式就漂亮地處理掉了。

--<...

  • Share this:

在 C# 要輸出正負符號,一個 Format 運算式就漂亮地處理掉了。

--
(999).ToString("+#;-#;+0"); // +999
(-999).ToString("+#;-#;+0"); // -999
(0).ToString("+#;-#;+0"); // +0

--
string.Format("{0:+#;-#;Zero}", 999); // +999
string.Format("{0:+#;-#;Zero}", -999); // -999
string.Format("{0:+#;-#;Zero}", 0); // Zero

https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings#the--section-separator


Tags:

About author
not provided
軟體跟料理一樣,都變成了每人每天的生活必需品。
View all posts